//
//  ZDBRankCenterViewController.m
//  ZDB
//
//  Created by 微笑吧阳光 on 2020/3/16.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBRankCenterViewController.h"
#import "SGPagingView.h"
#import "ZDBRankingViewController.h"
@interface ZDBRankCenterViewController ()
<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate,UINavigationControllerDelegate>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentCollectionView *pageContentCollectionView;
@property (nonatomic, assign) BOOL isPushNextVC;
@end

@implementation ZDBRankCenterViewController
-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =  RGBA(249, 249, 249, 1);
   
    [self setupNavigationBar];
}
- (void)setupNavigationBar {
    
    NSArray *titleArr = @[@"周榜", @"月榜"];
     SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.bottomSeparatorColor = [UIColor clearColor];
    configure.titleFont= [UIFont systemFontOfSize:17];
    configure.titleSelectedColor = [UIColor colorWithHexString:@"#ff2a2a"];
    configure.indicatorColor = [UIColor colorWithHexString:@"#ff2a2a"];
    configure.titleColor = [UIColor colorWithHexString:@"#1b1b1b"];
    CGFloat statusHeight = CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(UIScreenWidth/2-75, statusHeight, 150, 44) delegate:self titleNames:titleArr configure:configure];
    self.pageTitleView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_pageTitleView];
    ZDBRankingViewController *oneVC = [[ZDBRankingViewController alloc] init];
    oneVC.showType = 1;
    ZDBRankingViewController *twoVC = [[ZDBRankingViewController alloc] init];
    twoVC.showType = 2;
    NSArray *childArr = @[oneVC, twoVC];
     CGFloat pageTitleViewY = 0;
     if (statusHeight == 20.0) {
         pageTitleViewY = 64;
     } else {
         pageTitleViewY = 88;
     }
    CGFloat ContentCollectionViewHeight = UIScreenHeight - kStatusBarAndNavigationBarHeight-TABBAR_HEIGHT;
     self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, pageTitleViewY, self.view.frame.size.width, ContentCollectionViewHeight) parentVC:self childVCs:childArr];
     _pageContentCollectionView.delegatePageContentCollectionView = self;
     [self.view addSubview:_pageContentCollectionView];
    
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}

- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}

#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
 // 判断要显示的控制器是否是自己
  BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
  [self statusBarStyleIsDark:YES];
 [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
